package com.zhike.api.controller.system;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhike.common.dto.R;
import com.zhike.common.enums.ResultCode;
import com.zhike.common.exception.ZkimException;
import com.zhike.common.utils.ZkUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("api/zkim/sys")
@Api(tags = "系统模块")
@Slf4j
public class ZkController {

    @ApiOperation(value = "选IM服务")
    @GetMapping("selectServer")
    public R<String> selectServer() {
        try {
            String[] server = ZkUtil.getRandomServer();
            String host = server[0] + ":" + Integer.parseInt(server[1]);
            log.info("IM Server:{} Selected !!!", host);
            return R.success(host);
        } catch (Exception e) {
            throw new ZkimException(ResultCode.IM_SERVER_NONE);
        }
    }
}
